package com.honey.mybatis.generator.model;

import com.honey.compilation.java.AbstractJavaCompilation;
import com.honey.compilation.java.Clazz;
import com.honey.compilation.java.Field;
import com.honey.compilation.java.Method;
import com.honey.core.compiler.CompilationException;
import com.honey.core.dbmapping.introspect.IntrospectSchema;
import com.honey.core.dbmapping.introspect.IntrospectSchemaColumn;
import com.honey.mybatis.generator.AbstractProduceJavaCompilation;
import com.honey.mybatis.generator.MybatisPlugin;
import com.honey.mybatis.generator.model.method.GetResult1Method;
import com.honey.mybatis.generator.model.method.GetResult2Method;
import com.honey.mybatis.generator.model.method.SetParameterMethod;

public class ProduceModel extends AbstractProduceJavaCompilation {

	private Clazz clazz ;
	public ProduceModel(MybatisPlugin mybatisPlugin,
			IntrospectSchema introspectSchema,
			IntrospectSchemaColumn introspectSchemaColumn) {
		super(mybatisPlugin, introspectSchema, introspectSchemaColumn);
	}

	@Override
	public AbstractJavaCompilation produceCompilation() throws CompilationException {
		clazz = ( Clazz ) new ModelClass(mybatisPlugin, introspectSchema, introspectSchemaColumn).createJavaCompilation();
		return  clazz;
	}

	@Override
	public Field[] produceFields() throws CompilationException {
		
		return null;
	}

	@Override
	public Method[] produceMethods() throws CompilationException {
		Method[] answer = new Method[3];
		if( super.introspectSchema.getSchema().isIncludeEnumColumn() ){
			answer[0] = new SetParameterMethod(clazz , mybatisPlugin, introspectSchema, introspectSchemaColumn ).createMethod();
			answer[1] = new GetResult1Method(clazz , mybatisPlugin, introspectSchema, introspectSchemaColumn ).createMethod();
			answer[2] = new GetResult2Method(clazz , mybatisPlugin, introspectSchema, introspectSchemaColumn ).createMethod();
		}
		return answer;
	}
}
